package cnpm02.j2ee.group3.logic.dao.impl;

import java.util.List;

import javax.ejb.Stateless;
import javax.persistence.Query;

import org.jboss.seam.annotations.AutoCreate;
import org.jboss.seam.annotations.Name;

import cnpm02.j2ee.group3.logic.dao.generic.AbstractTranslationEntityDaoImpl;
import cnpm02.j2ee.group3.model.AbstractEntity;
import cnpm02.j2ee.group3.model.CityTranslation;
import cnpm02.j2ee.group3.model.SupportedLanguage;

/**
 * Dao implementation for {@link CityTranslationDao}.
 * 
 * @author BINH
 * @version 1.0
 * */
@Stateless
@Name(CityTranslationDao.COMPONENT_NAME)
@AutoCreate
public class CityTranslationDaoImpl extends
		AbstractTranslationEntityDaoImpl<CityTranslation> implements
		CityTranslationDao {

	@SuppressWarnings("unchecked")
	public List<CityTranslation> selectAllByLocale(SupportedLanguage language) {
		Query query = getEntityManager().createQuery(SELECT_ALL_BY_LOCALE_QUERY);
		query.setParameter("supportedLanguage", language);
		return query.getResultList();
	}

	@SuppressWarnings("unchecked")
	public List<CityTranslation> selectAll() {
		Query query = getEntityManager().createQuery(SELECT_ALL_QUERY);
		return query.getResultList();
	}

	public CityTranslation select(AbstractEntity entity,
			SupportedLanguage language) {
		Query query = getEntityManager().createQuery(SELECT_ENTITY_BY_LOCALE_QUERY);
		query.setParameter("city", entity);
		query.setParameter("supportedLanguage", language);
		return (CityTranslation) query.getSingleResult();
	}

}
